﻿using System;
using System.Data;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using SME.Food.Surperise.BLL;
using SME.Food.Surperise.Model;

namespace SME.Food.Tricon.Web.AdminJS.MenusManage
{
    public partial class MenusModify : System.Web.UI.Page
    {
        public string hid = "";
        public int id, postId;
        public string Menus_No = ""
            , Mem_Name = ""
            , Num = ""
            , Remark = ""
            , Money = ""
            , PostSelect = ""
            , User_No = ""
            , type = ""
            , AddMyMenuSelectedIds = "";

        public Bas_Menus_BLL Menusbll = new Bas_Menus_BLL();
        public Bas_Menus_Model MenusModel = new Bas_Menus_Model();
        public Bas_Dishes_BLL bll = new Bas_Dishes_BLL();
        public Menus_Dishes_BLL MenuDishesbll = new Menus_Dishes_BLL();
        public Menus_Dishes_Model MenusDishesModel = new Menus_Dishes_Model();
        protected void Page_Load(object sender, EventArgs e)
        {
            User_No= Request.QueryString["userNo"];
            string type = Request.QueryString["type"];
            if (type == "modify")
            {
                hid = "add";
            }
            if (type == "update")
            {
                hid = "update";
                Show();
            }
        }

        public void Show()
        {
            Menus_No = Request.QueryString["Menus_No"];
            MenusModel = Menusbll.GetModel(Menus_No);
            if (MenusModel != null)
            {
                Money = MenusModel.TotalMony.ToString();
                Num = MenusModel.TotalNum.ToString();
                User_No = MenusModel.Mem_No;
                Remark = MenusModel.Remark;
            }
            DataTable table = MenuDishesbll.GetList(" Menus_No in (" + Menus_No + ")").Tables[0];
            StringBuilder sb = new StringBuilder();
            if (table.Rows.Count > 0)
            {
                foreach (DataRow dr in table.Rows)
                {
                    AddMyMenuSelectedIds += dr["Dishes_No"] + ",";
                    Bas_Dishes_Model model = bll.GetModel(dr["Dishes_No"].ToString());
                    
                    //未点击编辑按钮时显示的列表
                    sb.Append("<tr ty='show'>");
                    sb.AppendFormat("<td  >{0}</td>", dr["Dishes_No"]);
                    sb.AppendFormat("<td  >{0}</td>", model.Dishes_Name);
                    sb.AppendFormat("<td  >{0}</td>", model.Dishes_Price);
                    sb.AppendFormat("<td >{0}</td>", dr["Num"]);
                    sb.Append("<td align='center'>");
                    sb.AppendFormat("<a title='确实要删除该记录吗?' onclick='Getdelete(this);' class='btnDel' rId='{0}' '></a>", dr["Dishes_No"]);
                    sb.AppendFormat("<a title='编辑' onclick='Getupdate(this);'  class='btnEdit' rId='{0}'></a>", dr["Dishes_No"]);
                    sb.Append("</td>");
                    sb.AppendFormat("</tr>");


                    ////点击编辑按钮时显示的列表
                    //sb.Append("<tr style='display:none;' ty='edit'>");
                    ////菜品编号
                    //sb.Append("<td >");
                    //sb.AppendFormat("<input hidty='foodId' type='hidden' name='line[{0}].ID' value='{1}'>",
                    //                dr["Dishes_No"], dr["Dishes_No"]);
                    ////拼接本次主键的id字符串，其实就是ids，记录就是根据ids进行筛选出来的
                    //sb.AppendFormat(
                    //    "<input type='text' style='float:left' readonly='readonly' size='16' name='lookup[{0}].DishesNo' value='{1}' lookuppk='id' size='12' class='required textInput readonly valid'>",
                    //    dr["Dishes_No"], dr["Dishes_No"]);
                    //sb.Append("</td>");

                    ////菜品名称
                    //sb.Append("<td >");
                    //sb.AppendFormat(
                    //    "<input type='text' readonly='readonly' name='lookup[{0}].DishesName' size='20' value='{1}' size='12' class='required textInput readonly'>",
                    //    dr["Dishes_No"], model.Dishes_Name);
                    //sb.Append("</td>");
                    ////菜品单价
                    //sb.Append("<td >");
                    //sb.AppendFormat(
                    //    "<input type='text' readonly='readonly' name='lookup[{0}].DishesPrice' value='{1}' size='12' class='required textInput readonly'>",
                    //    dr["Dishes_No"], model.Dishes_Price);
                    //sb.Append("</td>");
                    ////菜品数量
                    //sb.Append("<td >");
                    //sb.AppendFormat(
                    //    "<input type='text' id='Num  name='lookup[{0}].Num' value='{1}' size='12' class='required textInput'>", dr["Dishes_No"], dr["Num"]);
                    //sb.Append("</td>");
                    ////操作
                    //sb.Append("<td  ty='edit' align='center'>");
                    //sb.AppendFormat("<a title='确实要删除该记录吗?' class='btnDel' rId='{0}' '></a>", dr["Dishes_No"]);
                    //sb.Append("</td>");

                    //sb.AppendFormat("</tr>");

                    

                }
                MenusLitreal.Text = sb.ToString();
            }


        }
    }
}